package com.labtalk.admin.utils;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author G-pointy
 * @Date 2022/8/09
 * @Description: ResponseOutputUtil
 */
@Slf4j
public class ResponseOutputUtil {
    private static final Logger logger = LoggerFactory.getLogger(ResponseOutputUtil.class);

    public static void outputJson(HttpServletResponse response, Object object) {
        try {
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json");
            PrintWriter out = response.getWriter();
            out.write(JSON.toJSONString(object));
        } catch (IOException e) {
            logger.error(e.getMessage());
        }
    }
}
